<?php
	if(trim($_COOKIE["login_username"]) == ""){
		echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">";
		exit;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="SHOTCUT ICON" href="../image/administrator.ico">
<link href="../css/style.css" rel="stylesheet" type="text/css">
<title>Admin BizIT2010</title>
<style type="text/css">
	body {
		background-image: url(../images/bg_intro_01.jpg);
		background-repeat: repeat-x;
	}
</style>
<script type="text/javascript">
	function chk_pay(id_element, name_cs){
		var url='chk_pay.php?id='+id_element+'&cs_name='+encodeURIComponent(name_cs)+'&hash='+new Date().getTime()+Math.random();
		window.open(url, '_blank','scrollbars=yes,resizable=no,width=550,height=320');
	}
	function cf_pay(){
		if(confirm('ยืนยันว่าได้รับเงินแล้ว ?')==false){
			return 0;
		}
		document.getElementById("frm_cf_pay").submit();
	}
	function fn_exp(){
		alert(document.getElementById("rest_st_id").value);
		document.getElementById("if_exp").src='export_pdf.php?rest_st_id='+encodeURIComponent(document.getElementById("rest_st_id").value)+'&hash='+new Date().getTime()+Math.random();
	}
	function fn_ch2exp(){
		var obj_rest_id=document.getElementById("rest_id");
		var rest_id=obj_rest_id.options[obj_rest_id.selectedIndex].value;
		document.getElementById("rest_st_id").value=rest_id;
	}
</script>
</head>
<?
include("../config.php");
include("../include/function.php");
//$filter=trim($_POST["filter"]);
?>
<BODY BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
	<Table border="0" cellpadding="0" cellspacing="0" width="1054" align="center">
		<Tr>
			<td width="15">&nbsp;</td>
			<td width="1024" valign="top" height="600">
				<Table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="font_normal">
			  		<Tr>
						<td colspan="2" align="center"><? //include("../include/header.php");?></td>
					</Tr>
					<Tr bgcolor="#CCCCCC" height="1"><td colspan="2"></td></Tr>
					<Tr>
						<td width="20%" align="center" valign="top">
                        <br />
							<? include("menu.php");?>
						</td>
						<td width="80%" valign="top" bgcolor="#FFFFFF">
                        <br /><br />
					    	<TABLE WIDTH="750" BORDER="0" align="center" CELLPADDING="0" CELLSPACING="0" style="margin-top:5px;">
								<TR>
									<TD width="10" height="33" background="../image/control_03.gif"></TD>
									<TD height="33" align="center" background="../image/control_04.gif"><span class="tp1">ข้อมูลการลงทะเบียนเข้างาน</span></TD>
									<TD width="10" height="33" background="../image/control_05.gif"></TD>
								</TR>
								<TR>
									<TD width="10" background="../image/control_07.gif"></TD>
									<TD bgcolor="#FFFFFF" valign="top" align="left" height="450" class="font_normal">
                                    		<?
												$sql_rs="select reserve.*, rs_status.rsstatus, payment.transfer_date from reserve 
														LEFT JOIN rs_status ON (reserve.reserve_status=rs_status.rsstatus_id) 
														LEFT JOIN payment ON (reserve.reserve_id=payment.reserve_id)  
														";
												
												$sql="select * from customer ";
												$sql.=" LEFT JOIN  (".$sql_rs.") AS res ON (customer.customer_id=res.reservecus_id) ";
												
												/*if($filter != ""){
													$search[] = "LOWER(username) LIKE '%".strtolower($filter)."%'";
													$search[] = "LOWER(firstname) LIKE '%".strtolower($filter)."%'";
													$search[] = "LOWER(lastname) LIKE '%".strtolower($filter)."%'";
													$search[] = "LOWER(address) LIKE '%".strtolower($filter)."%'";
													$search[] = "LOWER(email) LIKE '%".strtolower($filter)."%'";
												}
											
												$sstr=count($search) == 0 ? '' : "(".implode(" OR ", $search).")";
												$sstr=(trim($sstr) == "") ? "" : "where  ".$sstr;
												
												$sql.=$sstr;*/
												if((int)$_POST["rest_id"] > 0){
													if($sstr != ""){
														$sql.=" and reserve_status=".(int)$_POST["rest_id"];
													}else{
														$sql.=" where reserve_status=".(int)$_POST["rest_id"];
													}
												}elseif($_POST["rest_id"] == "null"){
													if($sstr != ""){
														$sql.=" and reserve_status IS NULL";
													}else{
														$sql.=" where reserve_status IS NULL";
													}
												}
												$sql.=" order by customer_id";
												//echo $sql."<br>";
												mysql_db_query($dbm,"SET NAMES utf8");
												$result=mysql_query($sql, $connect);
												
												
												print "<form method=\"post\" action=\"register_topic.php\" enctype=\"multipart/form-data\">";
													/*print "<b>ค้นหา&nbsp;:&nbsp;</b>";
													print "&nbsp;&nbsp;<input type=\"text\" name=\"filter\" size=\"16\" value='".$filter."'>&nbsp;";*/
													$sql_st="select * from rs_status order by rsstatus_id";
													$result_st=mysql_db_query($dbm, $sql_st);
														print "<b>สถานะการเข้าร่วมงาน&nbsp;:&nbsp;</b>";
														print "<select id=\"rest_id\" name=\"rest_id\" onchange=\"fn_ch2exp();\">";
														print "<option value=\"all\">ALL</option>";
														print "<option value=\"null\"";
														if($_POST["rest_id"] == "null") print " selected";
														print ">ยังไม่ได้ลงทะเบียนจอง</option>";
														while($record=mysql_fetch_array($result_st, MYSQL_ASSOC)){
															print "<option value='".$record["rsstatus_id"]."' ";
															if($record["rsstatus_id"] == $_POST["rest_id"]) print " selected";
															print ">".$record["rsstatus"];
															print "</option>";
														}mysql_free_result($result_st);
														print "</select>";
													
													print "&nbsp;<input type=\"submit\" name=\"btn_search\" value=\"Search\">";
													//print "&nbsp;&nbsp;<img src=\"../image/pdf_img.jpeg\" border=\"0\" width=\"16\" ";
													//print "height=\"16\" style=\"cursor:pointer;\" onclick=\"fn_exp();\" title=\"export&nbsp;pdf\">";
												print "</form>";
												//print "<form id=\"form_exp\" method=\"post\" action=\"export_pdf.php\" enctype=\"multipart/form-data\">";
													print "<input type=\"hidden\" id=\"rest_st_id\" name=\"rest_st_id\">";
												//print "</form>";
												print "<br>";
												print "<iframe id=\"if_exp\" src=\"\" style=\"width:0px;height:0px;\" border=\"0\" frameborder=\"0\"></iframe>";
												if(mysql_num_rows($result) > 0){
													print "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
														
														$n=0;
														while($record=mysql_fetch_array($result, MYSQL_ASSOC)){
														$bg=(($n%2)==0) ? "#D4FFAA" : "#CCCCCC";
														print "<tr bgcolor='".$bg."'>";
															print "<td valign=\"top\" width=\"20\"><b><font color=\"#0000FF\">".($n+1).".</font></b></td>";
															print "<td>";
															print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" style=\"margin-top:5px;\">";
																print "<tr>";
																	print "<td align=\"right\"><b>ชื่อสมาชิก&nbsp;:&nbsp;</b></td>";
																	print "<td align=\"left\">".$record["firstname"]."&nbsp;&nbsp;".$record["lastname"]."</td>";
																	print "<td width=\"80\"></td>";
																	print "<td align=\"right\"><b>วันที่สมัครสมาชิก&nbsp;:&nbsp;</b></td>";
																	print "<td align=\"left\">".date("d/m/Y H:i:s", strtotime($record["register_date"]))."</td>";
																print "</tr>";
																print "<tr><td colspan=\"5\" height=\"3\"></td></tr>";
																
																print "<tr>";
																	print "<td align=\"right\"><b>อีเมลล์&nbsp;:&nbsp;</b></td>";
																	print "<td align=\"left\">".$record["email"]."</td>";
																	print "<td width=\"80\"></td>";
																	print "<td align=\"right\"><b>เบอร์โทรศัพท์&nbsp;:&nbsp;</b></td>";
																	print "<td align=\"left\">".$record["phone"]."</td>";
																print "</tr>";
																print "<tr><td colspan=\"5\" height=\"3\"></td></tr>";
																print "<tr>";
																	print "<td align=\"right\"><b>สถานะการเข้าร่วมงาน&nbsp;:&nbsp;</b></td>";
																	$rs_status="ยังไม่ได้ลงทะเบียนเข้าร่วมงาน";
																	if($record["rsstatus"] != NULL){
																		$rs_status=$record["rsstatus"];
																	}
																	print "<td align=\"left\"><font color=\"#0000FF\">".$rs_status."</font></td>";
																	print "<td width=\"80\"></td>";
																	print "<td align=\"right\"><b>วันที่ลงทะเบียนเข้าร่วมงาน&nbsp;:&nbsp;</b></td>";
																	print "<td align=\"left\">";
																	if(trim($record["reserve_date"]) != NULL) print date("d/m/Y H:i:s", strtotime($record["reserve_date"]));
																	else print "-";
																	print "</td>";																	
																print "</tr>";
																
																print "<tr><td colspan=\"5\" height=\"3\"></td></tr>";
																
																	print "<tr>";
																		print "<td align=\"right\"><b>วันเวลาโอนเงิน&nbsp;:&nbsp;</b></td>";
																		print "<td align=\"left\">";
																			if(trim($record["transfer_date"]) != NULL) print date("d/m/Y H:i:s", strtotime($record["transfer_date"]));
																			else print "-";
																		print "</td>";
																		print "<td width=\"80\"></td>";
																	if($record["reserve_status"] == 2 || $record["reserve_status"] == 3){
																		$cs_name=$record["firstname"]."&nbsp;&nbsp;".$record["lastname"];
																		print "<td align=\"left\" colspan=\"2\">";
																		print "&nbsp;&nbsp;&nbsp;<b><a href=\"javascript:void(0);\" ";
																			print "onclick=\"chk_pay('".$record["reserve_id"]."', '".$cs_name."');\" ";
																			print "class=\"class_a_normal\">รายละเอียดการชำระเงิน";
																		print "</a></b>";
																		print "</td>";
																	}
																	print "</tr>";
																print "<tr><td colspan=\"5\" height=\"3\"></td></tr>";
																print "<tr>";
																	print "<td align=\"center\" colspan=\"5\">";
																		print "<form id=\"frm_cf_pay\" method=\"post\" action=\"cof_upd.php\" enctype=\"multipart/form-data\">";
																			print "<input type=\"hidden\" name=\"action\" value=\"confirm_get_payment\">";
																			print "<input type=\"hidden\" name=\"rs_id\" value='".$record["reserve_id"]."'>";
																			if($record["reserve_status"] == 2){
																				print "<input type=\"button\" value=\"ยืนยันได้รับเงินแล้ว\" onclick=\"cf_pay();\"";
																					if($record["reserve_status"] == 1) print " disabled";
																				print ">";
																			}
																		print "</form>";
																	print "</td>";
																print "</tr>";
																/*print "<tr>";
																	print "<td align=\"right\"><b>Last&nbsp;Login&nbsp;:&nbsp;</b></td>";
																	print "<td align=\"left\">".date("d/m/Y H:i:s", strtotime($record["last_login"]))."</td>";
																	print "<td width=\"100\"></td>";
																	print "<td align=\"right\"><b>Last&nbsp;Logout&nbsp;:&nbsp;</b></td>";
																	print "<td align=\"left\">".date("d/m/Y H:i:s", strtotime($record["last_logout"]))."</td>";
																print "</tr>";*/
															print "</table>";
														print "</td></tr>";
															$n++;
														}
														
														mysql_free_result($result);
													print "</table>";
												}else{
													print "<br><center><b><span class=\"red\">ไม่มีข้อมูล !!! </span></b></center>";
												}
											?>
                                	</TD>
									<TD width="10" background="../image/control_09.gif"></TD>
								</TR>
								<TR>
									<TD width="10" height="8" background="../image/control_10.gif"></TD>
									<TD height="8" background="../image/control_11.gif"></TD>
									<TD width="10" height="8" background="../image/control_12.gif"></TD>
								</TR>
							</TABLE>
                        <br />
                        </td>
					</Tr>
					<Tr>
						<td colspan="2" align="center"><? //include("../include/footer.php");?></td>
					</Tr>
				</Table>   
		  </td>
			<td width="15">&nbsp;</td>
	  </Tr>
	</Table>
</BODY>
</html>
